package com.weixing.mall.provider.controller.cms;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.cms.CityAreaDto;
import com.weixing.mall.provider.model.query.CityAreaQuery;
import com.weixing.mall.provider.model.vo.cms.CityAreaCascaderVo;
import com.weixing.mall.provider.service.ICityAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CityAreaController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/26
 * @Version 1.0
 **/
@RestController
@RequestMapping("cityArea")
@Api(value = "行政区划APi", tags = "行政区划")
public class CityAreaController extends BaseController {

    @Autowired
    private ICityAreaService cityAreaService;

    @ApiOperation(value = "加载行政区划")
    @GetMapping("")
    public Result selectTreeList() {
        return ResultUtil.success(cityAreaService.selectTreeList());
    }

    @ApiOperation(value = "根据条件加载行政区划")
    @GetMapping("getCityArea")
    public Result getlist(CityAreaQuery cityAreaQuery) {
        return ResultUtil.success(cityAreaService.selectList(cityAreaQuery));
    }

    @ApiOperation(value = "根据条件分页加载行政区划")
    @GetMapping("getCityAreaPage")
    public Result list(CityAreaQuery cityAreaQuery) {
        return ResultUtil.success(cityAreaService.selectOfPage(initMpPage(),cityAreaQuery));
    }

    @ApiOperation(value = "保存行政区划信息")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated CityAreaDto cityAreaDto) {
        cityAreaService.save(cityAreaDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除行政区划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "行政区划id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return cityAreaService.removeById(id) ? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "查询-用于实体店铺 select级联")
    @GetMapping("form")
    public Result form(){
        List<CityAreaCascaderVo> list = cityAreaService.selectCityAreaCasaderVo();
        return ResultUtil.success(list);
    }
}
